home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume2 / fun / evo_life.1 next >
Internet Message Format  |  1988-12-07  |  22KB

  1. Path: xanth!ames!mailrus!ulowell!page
  2. From: page@swan.ulowell.edu (Bob Page)
  3. Newsgroups: comp.sources.amiga
  4. Subject: v02i094:  evo-life - evolving life simulation
  5. Message-ID: <10523@swan.ulowell.edu>
  6. Date: 6 Dec 88 23:52:41 GMT
  7. Organization: University of Lowell, Computer Science Dept.
  8. Lines: 495
  9. Approved: page@swan.ulowell.edu
  10.  
  11. Submitted-by: ain@k.cc.purdue.edu (Pat-bob White)
  12. Posting-number: Volume 2, Issue 94
  13. Archive-name: fun/evo-life.1
  14.  
  15. Here is an evolving life program I wrote several years ago in
  16. AmigaBasic.  I have other (extended) versions is anybody is
  17. interested.
  18.  
  19. #    This is a shell archive.
  20. #    Remove everything above and including the cut line.
  21. #    Then run the rest of the file through sh.
  22. #----cut here-----cut here-----cut here-----cut here----#
  23. #!/bin/sh
  24. # shar:    Shell Archiver
  25. #    Run the following text with /bin/sh to create:
  26. #    readme
  27. #    evolving_life_140
  28. #    tracefile
  29. # This archive created: Tue Nov 22 11:08:37 1988
  30. # By:    Pat-bob White (PUCC Land, USA)
  31. cat << \SHAR_EOF > readme
  32.    These two programs go together and were written in Amiga Basic.. first a
  33. bit about what they are and what they do:
  34.    Evolving Life 140 is a program I wrote about 2 years ago when I wanted to
  35. explore the concept of genetic learning.  I abstracted real life into an
  36. environment (sort of an electronic petri dish) and amoebe-like cells (sort of
  37. e-amoeba).
  38.    The environment consists of a 24x38 matrix of locations that cells can
  39. occupy.  Each location has a food level which is incremented by one each step,
  40. and is decrememnted when the cells eat.  The levels within the locations are
  41. represented by a spectrum from red to blue (red = lots of food).  One step is
  42. executed from each cell, then the environment is updated.. repeats till all
  43. cells die or the machine crashes :-)
  44.    The cells are represented by black dots in the locations.  They run 
  45. "genetic programs" that have 6 different kind of steps: move, reproduce, eat,
  46. goto, if hungry, and nop -- each step uses up internalized food.
  47.    Move: a cell tries to move to a (randomly selected) adjacent empty location,
  48.    Reproduce: reproduction is sexual; A cell on the make first finds a mate (a
  49.       cell in an adjacent location), then an empty adjacent location for the
  50.       child cell, and finally, creates the child cell's "genetic program" by
  51.       copying half from it's own program, and half from the mate's program.
  52.       Then, 1 random step in the new program is changed to a random value (on
  53.       the theory that mutations are good for the soul :-)
  54.    eat: internalize food from the environment (if there is any),
  55.    goto: goto a new step in the program (goes back to my own theory that loops
  56.       are essential to any programming language),
  57.    if hungry: if internalized food level is below some amount, then go to some
  58.       program step (same theory).. since I used bytes to represent each step,
  59.       this put a limt of 32 steps on the size of a program (I found out that
  60.       a cell only uses about 8 steps, but needed about 16 locations to save
  61.       them -- the other 8 steps being spent as wasted space... when I tried to
  62.       shorten the program to only 8 steps, I couldn't get colonies to start).
  63.    nop: every language needs one.. and what else was I to do with the other
  64.       3 3-bit patterns I wasn't using?
  65.    
  66.    There is a special cell that I used for keeping a tracefile -- cell 1.  (I
  67. represented the cells with an array of strings, so this was the cell in the
  68. first position of the array).  This cells is marked with a red dot in it's
  69. center, and each time a cell that is born reuses that array location, I write a
  70. snapshot of the current matrix, and where the cells are into the tracefile.
  71.  
  72.    The tracefile program is the other one here, and all it does is display
  73. a tracefile on the screen.  It's comments document it fairly well, so I won't
  74. bother to say anthing else about it.
  75.  
  76.  
  77. implementation:
  78.    Both programs are implemented in Amiga Basic, and I use the graphics
  79. heavily.. so a bit of description about Amiga graphics is in order for those
  80. who don't (aren't fortunate enough? :-) have an Amiga... (those who have an
  81. Amiga may find my terminology confusing since much of it is from the meager
  82. graphics background I have)
  83.    The Amiga has screens and windows.  A screen is where the colors (bitplanes)
  84. are defined, and the actual storage is attached to.  A window is a graphics
  85. viewport onto a screen that has it's own internal coordinate system.. when
  86. something is drawn into a window, the OS performs any necessary clipping and
  87. coordinate translation, and then actually renders it into the screen's memory
  88. (therefore, windows appear to have their own memory but really don't).
  89.    Therefore, I open a new 32-color screen to get access to a whole set of 32
  90. colors, open a window on it to render into, and then start rendering.  One
  91. confusing call (basic's fault, not mine) is the line drawing command, which I
  92. use to draw filled rectangles by specifying the upper left and lower right
  93. corners of the rectangle, and adding the "bf" option to draw a box and fill it.
  94.    PALLETTE sets a color in the pallette.
  95.    POINT returns the color of the referenced pixel.
  96.    LOCATE moves the cursor to the desired character position.
  97.    CVI converts a two byte string to the integer it represents in binary
  98. (it's much the same as "asc() * 256 + asc()").
  99.    MKI$ is the opposite of CVI -- converts an integer into a string containing
  100. the 2-byte binary representation.
  101.  
  102.  
  103.    These are the comments from the evolving life program and it's corresponding
  104. tracefile program:
  105.  
  106. Evolving Life 140
  107. -----------------
  108. max number of cells is 140
  109. cells are kept as basic strings
  110. there are 8 types of program steps a cell program knows: move,
  111. reproduce, eat, goto, if hungry, and 3 nop's.  move moves a cell in
  112. any 1 of te 8 possible directions, eat takes food from the environment,
  113. goto unconditionally branches to another step i the program, if hungry
  114. branches if the cell is hungry, and nop's do nothing.  All actions
  115. cause food consumption of the internalized food (via eat).
  116.    death is caused by falling off the end of the program, running out
  117. of food, or executing more than the max number of steps allowed (the
  118. lifespan).
  119.    A trace snapshot is written to a file each time a cell is born into
  120. cell 1's storage (the cell storage is reused since I have only a small
  121. number of them -- so, everytime a cell is born that reuses storage
  122. position 1, a snapshot is taken).  The snapshots files are generally
  123. large (>200K) and are viewed through the "Tracefile" program.
  124.    Food levels are represented by a spectrum of colors -- red is max
  125. food, dark blue is min (somehow, purple slipped in as a high-but-not-
  126. max color for food.. don't really know why, but I suspect it is because
  127. I didn't want it to feel lonely :-)
  128.    The program runs till all the cells die.. alt least it is supposed to
  129. do that.
  130.   The stats at the bottome are: nc = number of currently alive cells,
  131. tc = total number of cells that have ever lived or are currently living,
  132. ns = total number of cell-program steps have been done.
  133.    Have fun reading the code -- it is commented but mostly consists of
  134. mid$ accesses to get characters out of the cell storage -- the cell's
  135. program steps are stored as characters in a basic string. 
  136.  
  137.  
  138. Tracefile
  139. ---------
  140. Tracefile -- written to display the trace files saved by
  141.  Evolving Live 140.  Written sometime arround 6/86
  142. Patrick White
  143. currently (11/88) reachable at ain@k.cc.purdue.edu
  144.  
  145. displays the tracefile -- one frame at a time.  the stats at the bottom
  146. of the picture are: which screen is being displayed, (nc) the number of
  147. cells on the screen, (tc) the total number of cells that have ever
  148. lived, (ns) the total number of cell-program-steps that have been
  149. executed.
  150. The colors on the screen indicate: red is most food, dark blue is least
  151. food.  THe outer square is the fool level scaled on a screen-wise basis
  152. with red being greatest amount of food.  The inner square is the food
  153. level scaled from 0 to max possible - again red is max.  I did it this
  154. way because I couldn't decided how to do it -- so, naturally, I did it
  155. both ways :-)
  156.   When finished with the data file, the program waits for a mouse-click
  157. in the display window before closing the window/screen.  If you stop
  158. the program in any other way, the screen and window will be left open
  159. and take memory -- best to let it finish on it's own.
  160.  Oh, BTW, trace snapshots are taken whenever a cell is born into cell 1
  161. (since I have to reuse the cell locations, this makes soms sense).
  162.  
  163.  
  164.    I also have a version in C for the Amiga somewhere -- I didn't submit it
  165. because I'm not sure if it even compiles anymore -- if you want it, let me know
  166. and I'll send it to you.
  167.  
  168.  
  169.  
  170.    Well, that's about it... (I think it's documented enough now :-)
  171. If you have any questions, please ask...
  172.  
  173. -- Pat White
  174. ARPA/UUCP: k.cc.purdue.edu!ain  BITNET: PATWHITE@PURCCVM  PHONE: (317) 743-8421
  175. U.S.  Mail:  320 Brown St. apt. 406,    West Lafayette, IN 47906
  176. SHAR_EOF
  177. cat << \SHAR_EOF > evolving_life_140
  178. REM Evolving Life 140 (140 cells max)
  179. REM Patrick White  written -- I have no idea but somewhere around 6/86
  180. REM currently (11/88) reachable at ain@k.cc.purdue.edu
  181.  
  182. REM max number of cells is 140
  183. REM cells are kept as basic strings
  184. REM there are 8 types of program steps a cell program knows: move,
  185. REM reproduce, eat, goto, if hungry, and 3 nop's.  move moves a cell in
  186. REM any 1 of te 8 possible directions, eat takes food from the environment,
  187. REM goto unconditionally branches to another step i the program, if hungry
  188. REM branches if the cell is hungry, and nop's do nothing.  All actions
  189. REM cause food consumption of the internalized food (via eat).
  190. REM    death is caused by falling off the end of the program, running out
  191. REM of food, or executing more than the max number of steps allowed (the
  192. REM lifespan).
  193. REM    A trace snapshot is written to a file each time a cell is born into
  194. REM cell 1's storage (the cell storage is reused since I have only a small
  195. REM number of them -- so, everytime a cell is born that reuses storage
  196. REM position 1, a snapshot is taken).  The snapshots files are generally
  197. REM large (>200K) and are viewed through the "Tracefile" program.
  198. REM    Food levels are represented by a spectrum of colors -- red is max
  199. REM food, dark blue is min (somehow, purple slipped in as a high-but-not-
  200. REM max color for food.. don't really know why, but I suspect it is because
  201. REM I didn't want it to feel lonely :-)
  202. REM    The program runs till all teh cells die.. alt least it is supposed to
  203. REM do that.
  204. REM   The stats at teh bottome are: nc = number of currently alive cells,
  205. REM tc = total number of cells that have ever lived or are currently living,
  206. REM ns = total number of cell-program steps have been done.
  207. REM    Have fun reading the code -- it is commented but mostly consists of
  208. REM mis$ accesses to get characters out of the cell storage -- the cell's
  209. REM program steps are stored as characters in a basic string. 
  210.  
  211. REM   life
  212.    CLEAR,20000,5000
  213.    RANDOMIZE TIMER
  214.    INPUT "filename of trace file ";filename$ : OPEN "O",#1,filename$
  215.    ncels = 139 : nstps = 50 : clrs = 16 : alimit = 94 : ns& = 0
  216.    nc% = 0 : tc& = 0
  217.    DIM food%(37,23), cell$(ncels)
  218.    
  219.    REM   initialize screen
  220.    SCREEN 1,300,200,4,1
  221.    WINDOW 2,"Evolving Life Display",(0,0)-(290,180),0,1
  222.    PALETTE 0, 0,0,0 : PALETTE 1, 0,0,1 : PALETTE 2, 0,.29,1
  223.    PALETTE 3, 0,.57,1 : PALETTE 4, 0,.86,1 : PALETTE 5, 0,1,.86
  224.    PALETTE 6, 0,1,.57 : PALETTE 7, 0,1,.29 : PALETTE 8, 0,1,0
  225.    PALETTE 9, .29,1,0 : PALETTE 10,.57,1,0 : PALETTE 11,.86,1,0
  226.    PALETTE 12,1,.86,0 : PALETTE 13,1,.57,0 : PALETTE 14,1,.29,0
  227.    PALETTE 15,1,0,0 : CLS : mf = 8510 : stp = mf / (clrs - 2)
  228.    FOR i = 0 TO 37
  229.       FOR j = 0 TO 23
  230.          food%(i,j) = i*j*10
  231.          LINE (i*7,j*7)-(i*7+6,j*7+6),(INT(food%(i,j) / stp) + 1),bf   
  232.       NEXT j
  233.    NEXT i
  234.    FOR i = 9 TO 15 : LINE (266,i*7+2)-(272,i*7+4),15,bf : NEXT i
  235.          
  236.    REM   initialize cells
  237.    FOR c = 0 TO 69
  238.       x = INT (RND * 38) : y = INT (RND * 24)
  239.       IF POINT(x*7+3,y*7+3) > 0 THEN
  240.          a% = INT (RND * mf) : b% = INT (RND * mf / 2)
  241.          cell$(c) = CHR$(x) + CHR$(y) + MKI$(a%) + MKI$(b%) + MKI$(INT(RND*alimit)) + MKI$(0)
  242.          LINE (x*7+2,y*7+2)-(x*7+4,y*7+4),0,bf 
  243.          FOR i = 1 TO nstps : x = INT (RND * 256) : cell$(c) = cell$(c) + CHR$(x) : NEXT i
  244.          nc% = nc% + 1
  245.       END IF
  246.    NEXT c
  247.    tc& = nc%
  248.    LOCATE 22,1 : PRINT "fre= ";FRE(0);FRE(-1);FRE(-2);
  249.    GOSUB pic
  250.    
  251.    REM quit stuff
  252.    ON ERROR GOTO e
  253.    ON MOUSE GOSUB quit
  254.    MOUSE ON
  255.    
  256. runagain:   REM   run cell programs
  257.    REM   increment food in environment
  258.    PALETTE 0,.2,.2,.2 : ns& = ns& + 1
  259.    FOR i = 0 TO 37
  260.       FOR j = 0 TO 23
  261.          a% = food%(i,j) : food%(i,j) = a% + 1 : IF food%(i,j) > mf THEN food%(i,j) = mf
  262.          IF INT(a% / stp) <> INT(food%(i,j) / stp) THEN
  263.             x = POINT(i*7+3,j*7+3) : LINE (i*7,j*7)-(i*7+6,j*7+6),INT(food%(i,j) / stp) + 1,bf
  264.             IF x = 0 THEN LINE (i*7+2,j*7+2)-(i*7+4,j*7+4),0,bf
  265.          END IF
  266.       NEXT j
  267.    NEXT i
  268.    PALETTE 0,0,0,0
  269.    
  270.    FOR c = 0 TO ncels
  271.       IF cell$(c) <> "" THEN
  272.          x = ASC( MID$( cell$(c),1,1)) : y = ASC( MID$( cell$(c),2,1))
  273.          IF (CVI( MID$(cell$(c), 7,2)) > alimit) OR (CVI( MID$( cell$(c), 3, 2)) < 0) THEN
  274.             LINE (x*7,y*7)-(x*7+6,y*7+6),INT(food%(x,y)/ stp)+1, bf
  275.             cell$(c) = "" : nc% = nc% - 1
  276.          ELSE
  277.             MID$(cell$(c), 7,2) = MKI$( CVI( MID$(cell$(c),7,2)) + 1) 
  278.             IF (y > 8) AND (y < 16) THEN MID$( cell$(c), 11 + INT(RND*(LEN(cell$(c))-10)), 1) = CHR$( INT(RND*256) )
  279.             a% = CVI( MID$( cell$(c), 9, 2) ) : y = ASC( MID$( cell$(c), 11 + a%, 1) )
  280.             a% = a% + 1
  281.             IF a% > (LEN( cell$(c)) - 11) THEN : MID$( cell$(c), 7, 2) = MKI$( alimit + 1) : a% = 0            
  282.             MID$( cell$(c), 9, 2) = MKI$( a% )
  283.             ON (y AND 7)+1 GOSUB mov, repro, eat, gto, ifhung, nop, nop, nop
  284.          END IF
  285.       END IF
  286.    NEXT c      
  287.    LOCATE 22,1 : PRINT "nc="; nc%;"  tc=";tc&;"  ns=";ns&; 
  288.    GOTO runagain
  289.  
  290. e:  WINDOW CLOSE 2 : SCREEN CLOSE 1 : CLOSE #1 : prinr ERR
  291.     END    
  292.    
  293. pic:   REM store a picture of the screen   
  294.    WRITE #1,mf;stp;ns&;tc&;nc%;cell$(0)
  295.    FOR i = 0 TO 37
  296.       WRITE #1,food%(i,0);food%(i,1);food%(i,2);food%(i,3);food%(i,4);food%(i,5);food%(i,6);food%(i,7);food%(i,8);food%(i,9);food%(i,10);food%(i,11)
  297.       WRITE #1,food%(i,12);food%(i,13);food%(i,14);food%(i,15);food%(i,16);food%(i,17);food%(i,18);food%(i,19);food%(i,20);food%(i,21);food%(i,22);food%(i,23)
  298.    NEXT i
  299.    FOR i = 0 TO ncels : IF cell$(i) <> "" THEN WRITE #1,MID$(cell$(i),1,2)
  300.    NEXT i
  301. RETURN
  302.       
  303. quit:   REM end
  304.    WINDOW CLOSE 2 : SCREEN CLOSE 1 : CLOSE #1
  305.    PALETTE 0, 0,.5,1 : PALETTE 1, 1,1,1 : PALETTE 2, 0,0,0
  306.    PALETTE 3, 1,.73,0
  307.    END
  308.  
  309. nop:   REM no op
  310.    MID$(cell$(c), 3, 2) = MKI$( CVI( MID$( cell$(c), 3, 2)) - 10) : RETURN   
  311.  
  312. mov:   REM move in specified direction
  313.    MID$( cell$(c), 3, 2) = MKI$( CVI( MID$( cell$(c), 3,2) ) - 20)
  314.    
  315.    REM   erase old cell position
  316.    a% = (y AND 224) / 32
  317.    x = ASC( MID$( cell$(c), 1, 1) ) : y = ASC( MID$( cell$(c), 2, 1) ) : x1 = x : y1 = y
  318.    LINE (x*7,y*7)-(x*7+6,y*7+6),INT( food%(x,y) / stp) + 1,bf
  319.    
  320.    REM   pick direction and move cell if possible   
  321.    IF a% = 0 THEN x = x - 1: y = y - 1
  322.    IF a% = 1 THEN y = y - 1
  323.    IF a% = 2 THEN y = y - 1: x = x + 1
  324.    IF a% = 3 THEN x = x + 1
  325.    IF a% = 4 THEN x = x + 1: y = y + 1
  326.    IF a% = 5 THEN y = y + 1
  327.    IF a% = 6 THEN y = y + 1: x = x - 1
  328.    IF a% = 7 THEN x = x - 1
  329.    
  330.    x = (x + 38) MOD 38
  331.    y = (y + 24) MOD 24
  332.    IF POINT( x*7 + 3, y*7 + 3) <> 0 THEN
  333.       MID$(cell$(c), 1, 1) = CHR$( x ) : MID$(cell$(c), 2, 1) = CHR$( y )
  334.       LINE (x*7+2, y*7+2)-(x*7+4,y*7+4),0,bf
  335.    ELSE
  336.       LINE (x1*7+2, y1*7+2)-(x1*7+4, y1*7+4),0,bf
  337.    END IF
  338. RETURN
  339.  
  340. repro:   REM reproduce if a cell nearby
  341.    MID$( cell$(c), 3, 2) = MKI$( CVI( MID$( cell$(c), 3, 2)) - 60)
  342.    IF nc% = ncels THEN RETURN   
  343.    
  344.    REM determine which cell to mate with
  345.    a% = 0 : b% = 0 : x1 = ASC( MID$( cell$(c),1,1)) : y1 = ASC( MID$( cell$(c),2,1)) 
  346. l1: IF (cell$(a%) <> "") AND (a% <> c) THEN
  347.        x = ASC( MID$( cell$(a%), 1, 1) ) : y = ASC( MID$( cell$(a%), 2, 1) )
  348.        IF ((x<x1-1) OR (x>x1+1) OR (y<y1-1) OR (y>y1+1)) AND (a% < ncels) THEN a%=a%+1 : b% = 1
  349.     ELSE
  350.        IF a% < ncels THEN a% = a% + 1 : b% = 1    
  351.     END IF
  352.    IF b% = 1 THEN b% = 0 : GOTO l1
  353.    IF (c = a%) OR (cell$(a%) = "") OR (x<x1-1) OR (x>x1+1) OR (y<y1-1) OR (y>y1+1) THEN RETURN
  354.    
  355.    REM determine free cell
  356.    b% = 0
  357. l2: IF (cell$(b%) <> "") AND (b% < ncels) THEN b% = b% + 1 : GOTO l2
  358.    IF cell$(b%) <> "" THEN RETURN   
  359.    
  360.    REM find empty spot for child cell
  361.    c% = x1 : d% = y1
  362.    FOR i = 1 TO 15
  363.       x = INT(RND * 3) - 1 + x1 : y = INT(RND * 3) - 1 + y1
  364.       IF ((POINT(x*7+3,y*7+3) > 0) AND (x > 0) AND (x < 38) AND (y > 0) AND (y < 24)) THEN c% = x : d% = y
  365.    NEXT i 
  366.    IF ((c% = x1) AND (d% = y1)) THEN RETURN  
  367.    
  368.    REM create child
  369.    nc% = nc% + 1 : tc& = tc& + 1
  370.    x = LEN( cell$(c) ) : y = LEN( cell$(a%) )
  371.    cell$(b%) = MID$(cell$(c), 1, INT(x / 2) ) + MID$(cell$(a%), INT(y / 2), y - INT(y / 2) )
  372.    MID$(cell$(b%), 1, 1) = CHR$(c%) : MID$(cell$(b%), 2, 1) = CHR$(d%)
  373.    LINE (c%*7+2,d%*7+2)-(c%*7+4,d%*7+4),0,bf
  374.    a% = INT( CVI( MID$( cell$(c), 3, 2) ) / 2)
  375.    MID$( cell$(c), 3, 2) = MKI$( a% ) : MID$( cell$(b%), 3, 2)= MKI$( a% )
  376.    MID$(cell$(b%), 7, 2) = MKI$( 0 ) : MID$(cell$(b%), 9, 2) = MKI$( 0 )
  377.        
  378.    REM mutate one step in child   
  379. REM   x = LEN( cell$(b%) )
  380. REM   a = RND : b = RND : MID$( cell$(b%), 11 + INT( a * (x - 10)), 1) = CHR$( INT( b * 256 ))
  381.    IF b% = 0 THEN GOSUB pic
  382. RETURN
  383.    
  384. eat:   REM eat food
  385.    MID$( cell$(c), 3, 2) = MKI$( CVI( MID$( cell$(c), 3, 2)) - 20)
  386.    x = ASC( MID$( cell$(c), 1, 1)) : y = ASC( MID$( cell$(c), 2, 1))
  387.    IF food%(x,y) > 100 THEN
  388.       food%(x,y) = food%(x,y) - 100
  389.       MID$( cell$(c), 3,2) = MKI$( CVI( MID$(cell$(c),3,2)) + 100)
  390.    ELSE
  391.       MID$( cell$(c), 3,2) = MKI$( CVI( MID$(cell$(c),3,2)) + food%(x,y))
  392.       food%(x,y) = 0
  393.    END IF
  394.    LINE (x*7,y*7)-(x*7+6,y*7+6),INT(food%(x,y)/ stp) + 1,bf
  395.    LINE (x*7+2,y*7+2)-(x*7+4,y*7+4),0,bf  
  396. RETURN
  397.  
  398. gto:   REM jump in program
  399.    MID$( cell$(c), 3, 2) = MKI$( CVI( MID$( cell$(c), 3, 2)) - 20)
  400.    a% = CVI( MID$( cell$(c), 9, 2)) : a% = ASC( MID$( cell$(c), a% + 11, 1)) MOD (LEN(cell$(c)) - 10)
  401.    MID$( cell$(c), 9,2) = MKI$( a% )
  402. RETURN
  403.  
  404. ifhung:   REM  if hungry then jump in program
  405.    MID$( cell$( c), 3,2) = MKI$( CVI( MID$( cell$(c), 3,2)) -40)
  406.    a% = CVI( MID$( cell$(c), 9, 2)) : x = ASC( MID$( cell$(c), a% + 11, 1)) MOD (LEN(cell$(c)) - 10)
  407.    IF CVI( MID$( cell$(c), 3,2)) < CVI( MID$( cell$(c), 5,2)) THEN a% = x ELSE a% = a% + 1
  408.    IF a% > (LEN(cell$(c)) - 11) THEN a% = 0
  409.    MID$( cell$(c), 9, 2) = MKI$( a% )
  410. RETURN   
  411. SHAR_EOF
  412. cat << \SHAR_EOF > tracefile
  413. REM Tracefile -- written to display the trace files saved by
  414. REM  Evolving Live 140.  Written sometime arround 6/86
  415. REM Patrick White
  416. REM currently (11/88) reachable at ain@k.cc.purdue.edu
  417.  
  418. REM displays the tractefile -- one frame at a time.  the stats at the bottom
  419. REM of the picture are: which screen is being displayed, (nc) the number of
  420. REM cells on the screen, (tc) the total number of cells that have ever
  421. REM lived, (ns) the total number of cell-program-steps that have been
  422. REM executed.
  423. REM The colors on the screen indicate: red is most food, dark blue is least
  424. REM food.  THe outer square is the fool level scaled on a screen-wise basis
  425. REM with red being greatest amount of food.  The inner square is the food
  426. REM level scaled from 0 to max possible - again red is max.  I did it this
  427. REM way because I couldn't decided how to do it -- so, naturally, I did it
  428. REM both ways :-)
  429. REM   When finished with the data file, the program waits for a mouse-click
  430. REM in the display window before closing the window/screen.  If you stop
  431. REM the program in any other way, the screen and window will be left open
  432. REM and take memory -- best to let it finish on it's own.
  433. REM  Oh, BTW, trace snapshots are taken whenever a cell is born into cell 1
  434. REM (since I have to reuse the cell locations, this makes soms sense).
  435.  
  436. REM   trace viewer
  437.    INPUT "trace filename";filename$
  438.    OPEN "I",#1,filename$
  439.    DIM f%(37,23)
  440.    sc = 0
  441.    
  442.    SCREEN 1,300,200,4,1
  443.    WINDOW 2,filename$,(0,0)-(290,180),0,1
  444.    PALETTE 0, 0,0,0 : PALETTE 1, 0,0,1 : PALETTE 2, 0,.29,1
  445.    PALETTE 3, 0,.57,1 : PALETTE 4, 0,.86,1 : PALETTE 5, 0,1,.86
  446.    PALETTE 6, 0,1,.57 : PALETTE 7, 0,1,.29 : PALETTE 8, 0,1,0
  447.    PALETTE 9, .29,1,0 : PALETTE 10, .57,1,0 : PALETTE 11, .86,1,0
  448.    PALETTE 12, 1,.86,0 : PALETTE 13, 1,.57,1 : PALETTE 14, 1,.29,0
  449.    PALETTE 15, 1,0,0
  450.    
  451. nxt:
  452.    sc = sc + 1   
  453.    INPUT #1,mf,stp,ns&,tc&,nc%
  454.    c$ = INPUT$ (64, #1) : c$ = MID$( c$, 3, 60)
  455.    REM PRINT nc%;"***";c$;"***"
  456.    FOR i = 0 TO 37
  457.       INPUT #1,f%(i,0),f%(i,1),f%(i,2),f%(i,3),f%(i,4),f%(i,5),f%(i,6),f%(i,7),f%(i,8),f%(i,9),f%(i,10),f%(i,11)
  458.       INPUT #1,f%(i,12),f%(i,13),f%(i,14),f%(i,15),f%(i,16),f%(i,17),f%(i,18),f%(i,19),f%(i,20),f%(i,21),f%(i,22),f%(i,23)
  459.    NEXT i
  460.  
  461.    max = f%(0,0)
  462.    FOR i = 0 TO 37 : FOR j = 0 TO 23
  463.       IF f%(i,j) > max THEN max = f%(i,j)
  464.    NEXT j : NEXT i
  465.    mstp = max / 14
  466.       
  467.    FOR i = 0 TO 37
  468.       FOR j = 0 TO 23
  469.          LINE (i*7,j*7)-(i*7+6,j*7+6),INT(f%(i,j) / mstp) + 1,b
  470.          LINE (i*7+1,j*7+1)-(i*7+5,j*7+5),INT(f%(i,j) / stp) + 1,bf
  471.       NEXT j
  472.    NEXT i
  473.    
  474.    FOR i = 1 TO nc%
  475.       a$ = INPUT$ (5,#1) : x = ASC( MID$( a$, 2,1)) : y = ASC( MID$( a$, 3,1))
  476.       REM PRINT  i;"***";a$;"***",x, y
  477.       LINE (x*7+2,y*7+2)-(x*7+4,y*7+4),0,bf
  478.       IF i = 1 THEN LINE (x*7+3,y*7+3)-(x*7+3,y*7+3),15,bf
  479.    NEXT i
  480.    
  481.    LOCATE 22,1 : PRINT sc;"nc= ";nc%;"tc= ";tc&;"ns= ";ns&;
  482.    
  483.    IF EOF(1) THEN GOTO cnt ELSE GOTO nxt
  484.    
  485. cnt:
  486.    BEEP   
  487.    ON MOUSE GOSUB quit
  488.    MOUSE ON
  489. slp: SLEEP
  490.    GOTO slp
  491.    
  492. quit:   
  493.    CLOSE #1 : WINDOW CLOSE 2 : SCREEN CLOSE 1
  494.    PALETTE 0, .4,.6,1 : PALETTE 1, 1,1,1 : PALETTE 2, 0,0,0
  495.    PALETTE 3, 1,.73,0
  496.    END
  497.       
  498. SHAR_EOF
  499. #    End of shell archive
  500. exit 0
  501.  
  502.  
  503. -- 
  504. Bob Page, U of Lowell CS Dept.  page@swan.ulowell.edu  ulowell!page
  505. Have five nice days.
  506.